﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MxWeiXinPF.Common;
using MxWeiXinPF.BLL;
using System.Text;
using System.Web.UI.HtmlControls;

namespace MxWeiXinPF.Web.shopmgr.product
{
    public partial class product_add : MxWeiXinPF.Web.UI.ManagePage
    {
        private string action = MXEnums.ActionEnum.Add.ToString();
        protected MxWeiXinPF.Model.manager admin_info;
        private MxWeiXinPF.BLL.wx_shop_catalog_attribute caBll = new MxWeiXinPF.BLL.wx_shop_catalog_attribute();
        public int catalogId = 0;
        private MxWeiXinPF.BLL.wx_shop_product spBll = new MxWeiXinPF.BLL.wx_shop_product();
        private List<MxWeiXinPF.Model.wx_shop_productAttr_value> AddAttr()
        {
            List<MxWeiXinPF.Model.wx_shop_productAttr_value> list = new List<MxWeiXinPF.Model.wx_shop_productAttr_value>();
            string strContent = this.hidAttrValueStr.Value;
            if ((strContent == null) || (strContent.Trim() == ""))
            {
                return null;
            }
            string[] strArray = Utils.SplitString(strContent, "||");
            MxWeiXinPF.Model.wx_shop_productAttr_value item = new MxWeiXinPF.Model.wx_shop_productAttr_value();
            foreach (string str2 in strArray)
            {
                if (str2.Length > 0)
                {
                    string[] strArray2 = Utils.SplitString(str2, "_");
                    if ((strArray2 != null) && (strArray2.Length > 0))
                    {
                        item = new MxWeiXinPF.Model.wx_shop_productAttr_value
                        {
                            attributeId = new int?(MyCommFun.Str2Int(strArray2[1])),
                            paValue = MyCommFun.ObjToStr(strArray2[3])
                        };
                        list.Add(item);
                    }
                }
            }
            return list;
        }

        private List<MxWeiXinPF.Model.wx_shop_sku> AddSku()
        {
            List<MxWeiXinPF.Model.wx_shop_sku> list = new List<MxWeiXinPF.Model.wx_shop_sku>();
            string strContent = this.hidSkuVauleStr.Value;
            if ((strContent == null) || (strContent.Trim() == ""))
            {
                return null;
            }
            string[] strArray = Utils.SplitString(strContent, "||");
            MxWeiXinPF.Model.wx_shop_sku item = new MxWeiXinPF.Model.wx_shop_sku();
            foreach (string str2 in strArray)
            {
                if (str2.Length > 0)
                {
                    string[] strArray2 = Utils.SplitString(str2, "_");
                    if ((strArray2 != null) && (strArray2.Length > 0))
                    {
                        item = new MxWeiXinPF.Model.wx_shop_sku
                        {
                            attributeId = new int?(MyCommFun.Str2Int(strArray2[1])),
                            price = new decimal?(MyCommFun.Str2Int(strArray2[3])),
                            attributeValue = MyCommFun.ObjToStr(strArray2[5])
                        };
                        list.Add(item);
                    }
                }
            }
            return list;
        }

        private void BindAttrHtml(int catalogId)
        {
            IList<MxWeiXinPF.Model.wx_shop_productAttr_value> oldskulist = new List<MxWeiXinPF.Model.wx_shop_productAttr_value>();
            IList<MxWeiXinPF.Model.wx_shop_sku> list2 = new List<MxWeiXinPF.Model.wx_shop_sku>();
            bool flag = false;
            bool flag2 = false;
            int num = MyCommFun.Str2Int(this.hidCatalogId.Value);
            int num2 = MyCommFun.Str2Int(this.hidid.Value);
            if (catalogId == num)
            {
                MxWeiXinPF.BLL.wx_shop_productAttr_value _value = new MxWeiXinPF.BLL.wx_shop_productAttr_value();
                MxWeiXinPF.BLL.wx_shop_sku _sku = new MxWeiXinPF.BLL.wx_shop_sku();
                oldskulist = _value.GetModelList("productId=" + num2);
                if ((oldskulist != null) && (oldskulist.Count > 0))
                {
                    flag = true;
                }
                list2 = _sku.GetModelList("productId=" + num2);
                if ((list2 != null) && (list2.Count > 0))
                {
                    flag2 = true;
                }
            }
            IList<MxWeiXinPF.Model.wx_shop_catalog_attribute> modelList = new MxWeiXinPF.BLL.wx_shop_catalog_attribute().GetModelList("catalogId=" + catalogId + " order by sort_id asc");
            if ((modelList != null) && (modelList.Count > 0))
            {
                MxWeiXinPF.Model.wx_shop_catalog_attribute _attribute2 = new MxWeiXinPF.Model.wx_shop_catalog_attribute();
                StringBuilder builder = new StringBuilder();
                string str = "";
                string str2 = "";
                for (int i = 0; i < modelList.Count; i++)
                {
                    string[] strArray;
                    int num4;
                    _attribute2 = modelList[i];
                    if (_attribute2.aType.Value == 1)
                    {
                        builder.Append("<dl>");
                        builder.Append(" <dt>" + _attribute2.aName + "</dt>");
                        builder.Append("<dd>");
                        if ((_attribute2.aValue == null) || (_attribute2.aValue.Trim() == ""))
                        {
                            if (flag)
                            {
                                str = this.porductAttrValue(_attribute2.id, oldskulist);
                                builder.Append(string.Concat(new object[] { "<input name=\"txtattr\" type=\"text\" id=\"extattr_", _attribute2.id, "\" value=\"", str, "\" attrid=\"", _attribute2.id, "\" class=\"input normal txt_attr \" datatype=\"*0-200\" sucmsg=\" \" nullmsg=\" \">" }));
                            }
                            else
                            {
                                builder.Append(string.Concat(new object[] { "<input name=\"txtattr\" type=\"text\" id=\"extattr_", _attribute2.id, "\" attrid=\"", _attribute2.id, "\" class=\"input normal txt_attr \" datatype=\"*0-200\" sucmsg=\" \" nullmsg=\" \">" }));
                            }
                        }
                        else
                        {
                            strArray = Utils.SplitString(_attribute2.aValue, "\r\n");
                            if ((strArray != null) && (strArray.Length > 0))
                            {
                                builder.Append(string.Concat(new object[] { "<select name=\"ddlattr\" id=\"extattr_", _attribute2.id, "\" attrid=\"", _attribute2.id, "\"  class=\"txt_attr\">" }));
                                builder.Append("<option value=\"\">请选择...</option>");
                                if (flag)
                                {
                                    str = this.porductAttrValue(_attribute2.id, oldskulist);
                                    num4 = 0;
                                    while (num4 < strArray.Length)
                                    {
                                        if (str == strArray[num4])
                                        {
                                            builder.Append("<option value=\"" + strArray[num4] + "\" selected=\"selected\">" + strArray[num4] + "</option>");
                                        }
                                        else
                                        {
                                            builder.Append("<option value=\"" + strArray[num4] + "\">" + strArray[num4] + "</option>");
                                        }
                                        num4++;
                                    }
                                }
                                else
                                {
                                    num4 = 0;
                                    while (num4 < strArray.Length)
                                    {
                                        builder.Append("<option value=\"" + strArray[num4] + "\">" + strArray[num4] + "</option>");
                                        num4++;
                                    }
                                }
                                builder.Append("</select>");
                            }
                            builder.Append("");
                        }
                        builder.Append("</dd>");
                        builder.Append("</dl>");
                    }
                    else if ((_attribute2.aType.Value == 2) && ((_attribute2.aValue != null) && (_attribute2.aValue.Trim() != "")))
                    {
                        builder.Append("<dl>");
                        builder.Append(" <dt>" + _attribute2.aName + "</dt>");
                        builder.Append("<dd>");
                        strArray = Utils.SplitString(_attribute2.aValue, "\r\n");
                        if ((strArray != null) && (strArray.Length > 0))
                        {
                            builder.Append(" <table class=\"ltable tb_sku\">  <thead> <tr> <th width=\"80\"> 使用 </th> <th> 名称  </th> <th width=\"120\">  属性加价格 </th> </tr></thead>");
                            builder.Append("<tbody class=\"ltbody\">");
                            for (num4 = 0; num4 < strArray.Length; num4++)
                            {
                                builder.Append(" <tr class=\"td_c\">");
                                if (flag2)
                                {
                                    str2 = this.porductSkuPrice(_attribute2.id, strArray[num4], list2);
                                    if (str2 != "")
                                    {
                                        builder.Append(" <td>");
                                        builder.Append(string.Concat(new object[] { "<input id=\"chk_skuvalue_", num4, "\" type=\"checkbox\" attrid=\"", _attribute2.id, "\" class=\"skuchk\" checked=\"checked\" />" }));
                                        builder.Append("</td>");
                                        builder.Append(string.Concat(new object[] { " <td> <label for=\"chk_skuvalue_", num4, "\" class=\"skuattrName\">", strArray[num4], "</label> </td>" }));
                                        builder.Append("<td>");
                                        builder.Append("<input name=\"txtaddvalue\" type=\"text\"   id=\"txtaddvalue" + strArray[num4] + "\" value=\"" + str2 + "\" class=\"input small skuvaddmenoy\" datatype=\"*0-10\" sucmsg=\" \">");
                                        builder.Append("</td>");
                                    }
                                    else
                                    {
                                        builder.Append(" <td>");
                                        builder.Append(string.Concat(new object[] { "<input id=\"chk_skuvalue_", num4, "\" type=\"checkbox\" attrid=\"", _attribute2.id, "\" class=\"skuchk\"   />" }));
                                        builder.Append("</td>");
                                        builder.Append(string.Concat(new object[] { " <td> <label for=\"chk_skuvalue_", num4, "\" class=\"skuattrName\">", strArray[num4], "</label> </td>" }));
                                        builder.Append("<td>");
                                        builder.Append("<input name=\"txtaddvalue\" type=\"text\"   id=\"txtaddvalue" + strArray[num4] + "\" value=\"0\" class=\"input small skuvaddmenoy\" datatype=\"*0-10\" sucmsg=\" \">");
                                        builder.Append("</td>");
                                    }
                                }
                                else
                                {
                                    builder.Append(" <td>");
                                    builder.Append(string.Concat(new object[] { "<input id=\"chk_skuvalue_", num4, "\" type=\"checkbox\" attrid=\"", _attribute2.id, "\" class=\"skuchk\"   />" }));
                                    builder.Append("</td>");
                                    builder.Append(string.Concat(new object[] { " <td> <label for=\"chk_skuvalue_", num4, "\" class=\"skuattrName\">", strArray[num4], "</label> </td>" }));
                                    builder.Append("<td>");
                                    builder.Append("<input name=\"txtaddvalue\" type=\"text\"   id=\"txtaddvalue" + strArray[num4] + "\" value=\"0\" class=\"input small skuvaddmenoy\" datatype=\"*0-10\" sucmsg=\" \">");
                                    builder.Append("</td>");
                                }
                                builder.Append("</tr>");
                            }
                            builder.Append(" </tbody> </table>");
                        }
                        builder.Append("</dd>");
                        builder.Append("</dl>");
                    }
                }
                this.litAttr.Text = builder.ToString();
            }
        }

        private void bindCatalog()
        {
            try
            {
                IList<MxWeiXinPF.Model.wx_shop_catalog> modelList = new MxWeiXinPF.BLL.wx_shop_catalog().GetModelList("wid=" + "39");
                this.ddlCatalog.DataTextField = "cTitle";
                this.ddlCatalog.DataValueField = "id";
                this.ddlCatalog.DataSource = modelList;
                this.ddlCatalog.DataBind();
                this.ddlCatalog.Items.Insert(0, new ListItem("请选择商品类型", "0"));
            }
            catch (Exception ex)
            {
                
            }

        }

        private void BindProductInfo(int id)
        {
            MxWeiXinPF.BLL.wx_shop_product _product = new MxWeiXinPF.BLL.wx_shop_product();
            this.hidid.Value = id.ToString();
            MxWeiXinPF.Model.wx_shop_product model = _product.GetModel(id);
            if (model.categoryId.HasValue && (model.categoryId.ToString() != null))
            {
                this.ddlCategoryId.SelectedValue = model.categoryId.ToString();
            }
            if (!((model.catalogId.ToString() == null) || model.catalogId.ToString().Equals("")))
            {
                foreach (ListItem x in ddlCatalog.Items)
                {
                    if (x.Value.ToString() == model.catalogId.ToString())
                    {
                        this.ddlCatalog.SelectedValue = model.catalogId.ToString();
                        break;
                    }
                }
            }
            this.txtproductName.Text = model.productName;
            this.txtsku.Text = model.sku;
            if (model.upselling)
            {
                this.radType.Items[0].Selected = true;
            }
            else
            {
                this.radType.Items[1].Selected = true;
            }
            if (model.latest)
            {
                this.cblActionType.Items[0].Selected = true;
            }
            if (model.hotsale)
            {
                this.cblActionType.Items[1].Selected = true;
            }
            if (model.recommended)
            {
                this.cblActionType.Items[2].Selected = true;
            }
            if (model.specialOffer)
            {
                this.cblActionType.Items[3].Selected = true;
            }
            this.txtmarketPrice.Text = model.marketPrice.ToString();
            this.txtsort_id.Text = !model.sort_id.HasValue ? "99" : model.sort_id.ToString();
            this.txtshortDesc.Text = model.shortDesc;
            this.txtdescription.InnerText = model.description;
            this.txtspec.Text = model.spec;
            this.txtValidity.Text = model.validity;
            this.txtFactory.Text = model.factory;
            this.txtZhunzi.Text = model.zhunzi;
            this.txtSumQty.Text = model.sumqty.ToString();
            this.txtOneDayQty.Text = model.onedayqty.ToString();
            if ((model.extstr1 != null) && model.extstr1.Equals(""))
            {
                this.tbextstr1.Text = model.extstr1;
            }
            if (model.issendmessage)
            {
                this.rdbIsSendMessage.Items[0].Selected = true;
            }
            else
            {
                this.rdbIsSendMessage.Items[1].Selected = true;
            }
            this.txtDrugNumber.Text = model.drugnumber;
            this.rptAlbumList.DataSource = model.albums;
            this.rptAlbumList.DataBind();
            this.BindAttrHtml(model.catalogId);
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {

                string msgtitle = "";
                if (this.txtproductName.Text.Trim().Length == 0)
                {
                    msgtitle = msgtitle + @"商品名称不能为空！\n";
                }
                if (!MyCommFun.isNumber(this.txtSumQty.Text))
                {
                    msgtitle = msgtitle + @"商品总量格式错误！\n";
                }
                if (!MyCommFun.isNumber(this.txtOneDayQty.Text))
                {
                    msgtitle = msgtitle + @"每日用量格式错误！\n";
                }
                if (!MyCommFun.isDecimal(this.txtcostPrice.Text))
                {
                    msgtitle = msgtitle + @"成本格式错误！\n";
                }
                if (!MyCommFun.isDecimal(this.txtmarketPrice.Text))
                {
                    msgtitle = msgtitle + @"市场价格式错误！\n";
                }
                if (!MyCommFun.isDecimal(this.txtsalePrice.Text))
                {
                    msgtitle = msgtitle + @"销售价格式错误！\n";
                }
                if (!MyCommFun.isNumber(this.txtstock.Text))
                {
                    msgtitle = msgtitle + @"库存格式错误！\n";
                }
                if (!MyCommFun.isNumber(this.txtsort_id.Text))
                {
                    msgtitle = msgtitle + @"排序号格式错误！\n";
                }
                if (msgtitle != "")
                {
                    base.JscriptMsg(msgtitle, "back", "Error");
                }
                else
                {
                    int num8;
                    int num = 0;
                    if (GetRelativeAdminInfo() != null)
                    {
                        num = GetRelativeAdminInfo().id;
                    }
                    else {
                        num = GetAdminInfo().id;
                    }
                    int id = 39;
                    int num3 = int.Parse(this.ddlCategoryId.SelectedItem.Value);
                    int num4 = int.Parse(this.ddlCatalog.SelectedItem.Value);
                    int num5 = 0;
                    string text = this.txtsku.Text;
                    if (text.Trim() == "")
                    {
                        text = Utils.Number(8, true);
                    }
                    string str3 = this.txtproductName.Text;
                    string str4 = this.txtshortDesc.Text;
                    string str5 = "";
                    decimal num6 = 0M;
                    string str6 = this.txtdescription.Value;
                    bool flag = false;
                    bool flag2 = false;
                    bool flag3 = false;
                    bool flag4 = false;
                    int count = this.cblActionType.Items.Count;
                    for (num8 = 0; num8 < count; num8++)
                    {
                        if (this.cblActionType.Items[num8].Selected)
                        {
                            if (this.cblActionType.Items[num8].Value == "latest")
                            {
                                flag2 = true;
                            }
                            else if (this.cblActionType.Items[num8].Value == "hotsale")
                            {
                                flag3 = true;
                            }
                            else if (this.cblActionType.Items[num8].Value == "recommended")
                            {
                                flag = true;
                            }
                            else if (this.cblActionType.Items[num8].Value == "specialOffer")
                            {
                                flag4 = true;
                            }
                        }
                    }
                    decimal num9 = decimal.Parse(this.txtcostPrice.Text);
                    decimal num10 = decimal.Parse(this.txtmarketPrice.Text);
                    decimal num11 = decimal.Parse(this.txtsalePrice.Text);
                    bool flag5 = true;
                    if (this.radType.SelectedItem.Value == "2")
                    {
                        flag5 = false;
                    }
                    int num12 = int.Parse(this.txtstock.Text);
                    DateTime now = DateTime.Now;
                    int num13 = 0;
                    int num14 = int.Parse(this.txtsort_id.Text);
                    DateTime time2 = DateTime.Now;
                    string str7 = this.txtspec.Text.Trim();
                    string str8 = this.txtValidity.Text.Trim();
                    string str9 = this.txtFactory.Text.Trim();
                    string str10 = this.txtZhunzi.Text.Trim();
                    int num15 = int.Parse(this.txtSumQty.Text.Trim());
                    int num16 = int.Parse(this.txtOneDayQty.Text.Trim());
                    string str11 = this.txtDrugNumber.Text.Trim();
                    bool flag6 = false;
                    if (this.rdbIsSendMessage.SelectedItem.Value == "1")
                    {
                        flag6 = true;
                    }
                    MxWeiXinPF.Model.wx_shop_product model = new MxWeiXinPF.Model.wx_shop_product
                    {
                        wid = new int?(id),
                        categoryId = new int?(num3),
                        brandId = new int?(num5),
                        sku = text,
                        productName = str3,
                        shortDesc = str4,
                        unit = str5,
                        weight = new decimal?(num6),
                        description = str6,
                        recommended = flag,
                        latest = flag2,
                        hotsale = flag3,
                        specialOffer = flag4,
                        costPrice = new decimal?(num9),
                        marketPrice = new decimal?(num10),
                        salePrice = new decimal?(num11),
                        upselling = flag5,
                        stock = new int?(num12),
                        addDate = new DateTime?(now),
                        vistiCounts = new int?(num13),
                        sort_id = new int?(num14),
                        updateDate = new DateTime?(time2),
                        catalogId = num4,
                        shopid = num,
                        spec = str7,
                        validity = str8,
                        factory = str9,
                        zhunzi = str10,
                        sumqty = num15,
                        onedayqty = num16,
                        issendmessage = flag6,
                        drugnumber = str11,
                        extstr2 = this.tbextstr1.Text.Trim()
                    };
                    bool flag7 = false;
                    if (this.rdbIsRx.SelectedItem.Value == "1")
                    {
                        flag7 = true;
                    }
                    model.isRx = flag7;
                    string[] values = base.Request.Form.GetValues("hid_photo_name");
                    string[] strArray2 = base.Request.Form.GetValues("hid_photo_remark");
                    string[] strArray3 = base.Request.Form.GetValues("hid_photo_isdefault");
                    string str12 = "0";
                    if ((values != null) && (values.Length > 0))
                    {
                        if (strArray3.Contains("1"))
                        {
                            str12 = "1";
                        }
                        List<MxWeiXinPF.Model.wx_shop_albums> list = new List<MxWeiXinPF.Model.wx_shop_albums>();
                        for (num8 = 0; num8 < values.Length; num8++)
                        {
                            string[] strArray4 = values[num8].Split(new char[] { '|' });
                            if (strArray4.Length == 3)
                            {
                                if (!string.IsNullOrEmpty(strArray2[num8]))
                                {
                                    if (str12.Equals("1"))
                                    {
                                        if (!string.IsNullOrEmpty(strArray3[num8]))
                                        {
                                            MxWeiXinPF.Model.wx_shop_albums item = new MxWeiXinPF.Model.wx_shop_albums
                                            {
                                                original_path = strArray4[1],
                                                thumb_path = strArray4[2],
                                                remark = strArray2[num8],
                                                isdefault = strArray3[num8]
                                            };
                                            list.Add(item);
                                        }
                                        else
                                        {
                                            MxWeiXinPF.Model.wx_shop_albums _albums2 = new MxWeiXinPF.Model.wx_shop_albums
                                            {
                                                original_path = strArray4[1],
                                                thumb_path = strArray4[2],
                                                remark = strArray2[num8],
                                                isdefault = "0"
                                            };
                                            list.Add(_albums2);
                                        }
                                    }
                                    else if (num8 == 0)
                                    {
                                        MxWeiXinPF.Model.wx_shop_albums _albums3 = new MxWeiXinPF.Model.wx_shop_albums
                                        {
                                            original_path = strArray4[1],
                                            thumb_path = strArray4[2],
                                            remark = strArray2[num8],
                                            isdefault = "0"
                                        };
                                        list.Add(_albums3);
                                    }
                                    else
                                    {
                                        MxWeiXinPF.Model.wx_shop_albums _albums4 = new MxWeiXinPF.Model.wx_shop_albums
                                        {
                                            original_path = strArray4[1],
                                            thumb_path = strArray4[2],
                                            remark = strArray2[num8],
                                            isdefault = "0"
                                        };
                                        list.Add(_albums4);
                                    }
                                }
                                else if (str12.Equals("1"))
                                {
                                    if (!string.IsNullOrEmpty(strArray3[num8]))
                                    {
                                        MxWeiXinPF.Model.wx_shop_albums _albums5 = new MxWeiXinPF.Model.wx_shop_albums
                                        {
                                            original_path = strArray4[1],
                                            thumb_path = strArray4[2],
                                            isdefault = strArray3[num8]
                                        };
                                        list.Add(_albums5);
                                    }
                                    else
                                    {
                                        MxWeiXinPF.Model.wx_shop_albums _albums6 = new MxWeiXinPF.Model.wx_shop_albums
                                        {
                                            original_path = strArray4[1],
                                            thumb_path = strArray4[2],
                                            isdefault = "0"
                                        };
                                        list.Add(_albums6);
                                    }
                                }
                                else if (num8 == 0)
                                {
                                    MxWeiXinPF.Model.wx_shop_albums _albums7 = new MxWeiXinPF.Model.wx_shop_albums
                                    {
                                        original_path = strArray4[1],
                                        thumb_path = strArray4[2],
                                        isdefault = "1"
                                    };
                                    list.Add(_albums7);
                                }
                                else
                                {
                                    MxWeiXinPF.Model.wx_shop_albums _albums8 = new MxWeiXinPF.Model.wx_shop_albums
                                    {
                                        original_path = strArray4[1],
                                        thumb_path = strArray4[2],
                                        isdefault = "0"
                                    };
                                    list.Add(_albums8);
                                }
                            }
                        }
                        model.albums = list;
                    }
                    model.attrs = this.AddAttr();
                    model.skulist = this.AddSku();
                    int num17 = new MxWeiXinPF.BLL.wx_shop_product().Add(model);
                    base.AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "添加商品信息，商品信息主键id:" + num17);
                    string url = MyCommFun.QueryString("frompage");
                    if (url == "")
                    {
                        base.JscriptMsg("***商品录入成功,请继续录入***！", "product_add.aspx", "Success");
                    }
                    else
                    {
                        base.JscriptMsg("***商品录入成功***！", url, "Success");
                    }
                }

            }
            catch (Exception ex)
            {
                base.JscriptMsg("***商品录入成功***！", "product_add.aspx", "Success");
            }
        }

        protected void ddlCatalog_SelectedIndexChanged(object sender, EventArgs e)
        {
            int num = MyCommFun.Str2Int(this.ddlCatalog.SelectedItem.Value);
            IList<MxWeiXinPF.Model.wx_shop_catalog_attribute> modelList = new MxWeiXinPF.BLL.wx_shop_catalog_attribute().GetModelList("catalogId=" + num + " order by sort_id asc");
            if ((modelList != null) && (modelList.Count > 0))
            {
                MxWeiXinPF.Model.wx_shop_catalog_attribute _attribute2 = new MxWeiXinPF.Model.wx_shop_catalog_attribute();
                StringBuilder builder = new StringBuilder();
                for (int i = 0; i < modelList.Count; i++)
                {
                    string[] strArray;
                    int num3;
                    _attribute2 = modelList[i];
                    if (_attribute2.aType.Value == 1)
                    {
                        builder.Append("<dl>");
                        builder.Append(" <dt>" + _attribute2.aName + "</dt>");
                        builder.Append("<dd>");
                        if ((_attribute2.aValue == null) || (_attribute2.aValue.Trim() == ""))
                        {
                            builder.Append(string.Concat(new object[] { "<input name=\"txtattr\" type=\"text\" id=\"extattr_", _attribute2.id, "\" attrid=\"", _attribute2.id, "\" class=\"input normal txt_attr \" datatype=\"*0-200\" sucmsg=\" \" nullmsg=\" \">" }));
                        }
                        else
                        {
                            strArray = Utils.SplitString(_attribute2.aValue, "\r\n");
                            if ((strArray != null) && (strArray.Length > 0))
                            {
                                builder.Append(string.Concat(new object[] { "<select name=\"ddlattr\" id=\"extattr_", _attribute2.id, "\" attrid=\"", _attribute2.id, "\"  class=\"txt_attr\">" }));
                                builder.Append("<option value=\"\">请选择...</option>");
                                num3 = 0;
                                while (num3 < strArray.Length)
                                {
                                    builder.Append("<option value=\"" + strArray[num3] + "\">" + strArray[num3] + "</option>");
                                    num3++;
                                }
                                builder.Append("</select>");
                            }
                            builder.Append("");
                        }
                        builder.Append("</dd>");
                        builder.Append("</dl>");
                    }
                    else if ((_attribute2.aType.Value == 2) && ((_attribute2.aValue != null) && (_attribute2.aValue.Trim() != "")))
                    {
                        builder.Append("<dl>");
                        builder.Append(" <dt>" + _attribute2.aName + "</dt>");
                        builder.Append("<dd>");
                        strArray = Utils.SplitString(_attribute2.aValue, "\r\n");
                        if ((strArray != null) && (strArray.Length > 0))
                        {
                            builder.Append(" <table class=\"ltable tb_sku\">  <thead> <tr> <th width=\"80\"> 使用 </th> <th> 名称  </th> <th width=\"120\">  属性加价格 </th> </tr></thead>");
                            builder.Append("<tbody class=\"ltbody\">");
                            for (num3 = 0; num3 < strArray.Length; num3++)
                            {
                                builder.Append(" <tr class=\"td_c\">");
                                builder.Append(string.Concat(new object[] { " <td><input id=\"chk_skuvalue_", num3, "\" type=\"checkbox\" attrid=\"", _attribute2.id, "\" class=\"skuchk\"   /></td>" }));
                                builder.Append(string.Concat(new object[] { " <td> <label for=\"chk_skuvalue_", num3, "\" class=\"skuattrName\">", strArray[num3], "</label> </td>" }));
                                builder.Append("<td>");
                                builder.Append("<input name=\"txtaddvalue\" type=\"text\"   id=\"txtaddvalue" + strArray[num3] + "\" value=\"0\" class=\"input small skuvaddmenoy\" datatype=\"*0-10\" sucmsg=\" \">");
                                builder.Append("</td>");
                                builder.Append("</tr>");
                            }
                            builder.Append(" </tbody> </table>");
                        }
                        builder.Append("</dd>");
                        builder.Append("</dl>");
                    }
                }
                this.litAttr.Text = builder.ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!this.Page.IsPostBack)
                {
                    string str = MyCommFun.QueryString("frompage");
                    if (str != "")
                    {
                        this.litReturnPage.Text = "<a href=\"" + str + "\" class=\"back\"><i></i><span>返回</span></a>";
                    }
                    this.admin_info = GetRelativeAdminInfo() == null ? base.GetAdminInfo() : GetRelativeAdminInfo();
                    if (GetRelativeAdminInfo() != null)
                    {
                        this.btnSubmit.Visible = base.ChkAdminLevelExByRelative("onlineproduct", MXEnums.ActionEnum.Edit.ToString());
                    }
                    else {
                        this.btnSubmit.Visible = ChkAdminLevelEx("onlineproduct", MXEnums.ActionEnum.Edit.ToString());
                    }
                    
                    this.TreeBind();
                    this.bindCatalog();
                }
            }
            catch (Exception ex)
            {

            }
        }

        private string porductAttrValue(int attributeId, IList<MxWeiXinPF.Model.wx_shop_productAttr_value> oldskulist)
        {
            string paValue = "";
            IList<MxWeiXinPF.Model.wx_shop_productAttr_value> list = oldskulist.Where<MxWeiXinPF.Model.wx_shop_productAttr_value>(delegate(MxWeiXinPF.Model.wx_shop_productAttr_value e)
            {
                int? nullable1 = e.attributeId;
                int num = attributeId;
                return ((nullable1.GetValueOrDefault() == num) && nullable1.HasValue);
            }).ToArray<MxWeiXinPF.Model.wx_shop_productAttr_value>();
            if ((list != null) && (list.Count > 0))
            {
                paValue = list[0].paValue;
            }
            return paValue;
        }

        private string porductSkuPrice(int attributeId, string attributeValue, IList<MxWeiXinPF.Model.wx_shop_sku> oldskulist)
        {
            try
            {
                string str = "";
                IList<MxWeiXinPF.Model.wx_shop_sku> list = oldskulist.Where<MxWeiXinPF.Model.wx_shop_sku>(delegate(MxWeiXinPF.Model.wx_shop_sku e)
                {
                    int? nullable1 = e.attributeId;
                    int num = attributeId;
                    return (((nullable1.GetValueOrDefault() == num) && nullable1.HasValue) && (e.attributeValue == attributeValue));
                }).ToArray<MxWeiXinPF.Model.wx_shop_sku>();
                if ((list != null) && (list.Count > 0))
                {
                    str = !list[0].price.HasValue ? "0" : list[0].price.ToString();
                }
                return str;
            }
            catch (Exception ex)
            {
                
            }
            return "";
        }

        private void TreeBind()
        {
            try
            {
                DataTable wCodeList = new MxWeiXinPF.BLL.wx_shop_category().GetWCodeList(39, 0);
                this.ddlCategoryId.Items.Clear();
                this.ddlCategoryId.Items.Add(new ListItem("请选择类别...", ""));
                foreach (DataRow row in wCodeList.Rows)
                {
                    string str = row["id"].ToString();
                    int num = int.Parse(row["class_layer"].ToString());
                    string text = row["title"].ToString().Trim();
                    if (num == 1)
                    {
                        this.ddlCategoryId.Items.Add(new ListItem(text, str));
                    }
                    else
                    {
                        text = "├ " + text;
                        text = Utils.StringOfChar(num - 1, "　") + text;
                        this.ddlCategoryId.Items.Add(new ListItem(text, str));
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }

        private void BindProductInfoByChange(int id)
        {
            MxWeiXinPF.Model.wx_shop_product model = this.spBll.GetModel(id);
            if (model.categoryId.HasValue && (model.categoryId.ToString() != null))
            {
                this.ddlCategoryId.SelectedValue = model.categoryId.ToString();
            }
            this.hidCatalogId.Value = model.catalogId.ToString();
            this.txtproductName.Text = model.productName;
            this.txtsku.Text = model.sku;
            if (model.upselling)
            {
                this.radType.Items[0].Selected = true;
            }
            else
            {
                this.radType.Items[1].Selected = true;
            }
            if (model.latest)
            {
                this.cblActionType.Items[0].Selected = true;
            }
            if (model.hotsale)
            {
                this.cblActionType.Items[1].Selected = true;
            }
            if (model.recommended)
            {
                this.cblActionType.Items[2].Selected = true;
            }
            if (model.specialOffer)
            {
                this.cblActionType.Items[3].Selected = true;
            }
            this.txtcostPrice.Text = model.costPrice.ToString();
            this.txtmarketPrice.Text = model.marketPrice.ToString();
            this.txtsalePrice.Text = model.salePrice.ToString();
            this.txtstock.Text = model.stock.ToString();
            this.txtsort_id.Text = !model.sort_id.HasValue ? "99" : model.sort_id.ToString();
            this.txtshortDesc.Text = model.shortDesc;
            this.txtdescription.InnerText = model.description;
            this.txtspec.Text = model.spec;
            this.txtValidity.Text = model.validity;
            this.txtFactory.Text = model.factory;
            this.txtZhunzi.Text = model.zhunzi;
            this.txtSumQty.Text = model.sumqty.ToString();
            this.txtOneDayQty.Text = model.onedayqty.ToString();
            this.tbextstr1.Text = model.extstr2.ToString().Trim();
            if (model.issendmessage)
            {
                this.rdbIsSendMessage.SelectedIndex = 0;
            }
            else
            {
                this.rdbIsSendMessage.SelectedIndex = 1;
            }
            if (model.isRx)
            {
                this.rdbIsRx.SelectedIndex = 0;
            }
            else
            {
                this.rdbIsRx.SelectedIndex = 1;
            }
            this.txtDrugNumber.Text = model.drugnumber;
            this.rptAlbumList.DataSource = model.albums;
            this.rptAlbumList.DataBind();
            this.BindAttrHtml(model.catalogId);
        }

        protected void txtsku_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (!this.txtsku.Text.Trim().Equals(""))
                {
                    int maxIdByCode = new MxWeiXinPF.BLL.wx_shop_product().GetMaxIdByCode(this.txtsku.Text.Trim());
                    if (maxIdByCode > 0)
                    {
                        this.BindProductInfoByChange(maxIdByCode);
                    }
                }
            }
            catch (Exception ex)
            {
                
            }

        }
    }
}